package rabbitmq;

import java.time.LocalDateTime;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

import javax.annotation.Resource;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.amqp.AmqpException;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.core.MessagePostProcessor;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import com.sdu.dto.Order;

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(value = "classpath:delay-producer.xml")
public class DelayProducer {

	@Resource
	private RabbitTemplate rabbitTemplate;

	@Test
	public void send() {

		Order order = new Order();
		order.setDesc("话费充值");
		order.setPrice("50.00");
		order.setCreateTime(new Date());

		rabbitTemplate.convertAndSend("alipay", order, new MessagePostProcessor() {
			// 设置消息的有效期
			@Override
			public Message postProcessMessage(Message message) throws AmqpException {
				message.getMessageProperties().setExpiration("60000");
				return message;
			}
		});
	}
}
